package com.lovo.util.utils;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;

/**
 * 验证token
 */
public class VerifierUtil {
    public static String verifierJwt(String token){
        //私钥及加密算法
        Algorithm algorithm = Algorithm.HMAC256(CreateTokenUtil.TOKEN_SECRET);
        String json="";
        JWTVerifier verifier = JWT.require(algorithm).build();
        try {
            DecodedJWT jwt = verifier.verify(token); //认证token
            json=jwt.getClaim("info").asString();//取token中的信息
        }catch (Exception e){
            return  json;
        }
        return json;
    }
}
